cd
@echo off
:: arg0 is OUTPUT Dir
:: arg1 is Moc Input file
:: arg2 is UIC input file
:: arg3 is RCC input file

call:LOG_INIT

if not exist "%~1" goto ERROR_INVALID_OUTPUT_DIR 
if not exist "%~2" goto ERROR_INVALID_MOC_FILE
if not exist "%~3" goto ERROR_INVALID_UIC_FILE
if not exist "%~4" goto ERROR_INVALID_RCC_FILE

call:LOG_MESSAGE "Executing resources step"
for /f "tokens=*" %%a in (%~4) do (
call:execRcc %%a.qrc %~1/qrc_%%a.cpp
)

call:LOG_MESSAGE "Executing forms step"
for /f "tokens=*" %%a in (%~3) do (
call:execUic forms/%%a.ui %~1/ui_%%a.h
)

call:LOG_MESSAGE "Executing moc step"
for /f "tokens=*" %%a in (%~2) do (
call:execMoc include/%%a.h %~1/moc_%%a.cpp
)

goto:eof

:LOG_MESSAGE
	echo [%date% - %time%] %~1 >> GenerateQt.log 
	goto:eof
	
:LOG_INIT
	echo [%date% - %time%] Starting Log > GenerateQt.log 
	goto:eof
	
:ERROR_INVALID_APP_DIR
	call:LOG_MESSAGE "Invalid app dir !"
	goto:eof	
	
:ERROR_INVALID_OUTPUT_DIR
	call:LOG_MESSAGE "Invalid output dir !"
	goto:eof	
	
:ERROR_INVALID_MOC_FILE
	call:LOG_MESSAGE "File %~2 does not exist for moc !"
	goto:eof
	
:ERROR_INVALID_UIC_FILE
	call:LOG_MESSAGE "File %~3 does not exist for uic !"
	goto:eof
:ERROR_INVALID_RCC_FILE
	call:LOG_MESSAGE "File %~4 does not exist for rcc !"
	goto:eof
	
:execMoc
:: arg0 is filename
:: arg1 is output file
call:LOG_MESSAGE "Moc'ing %~1"
echo.Moc'ing "%~1"
%QTDIR%\bin\moc "%~1" -o "%~2"
goto:eof

:execUic
:: arg0 is filename
:: arg1 is output file
call:LOG_MESSAGE "Uic'ing %~1"
echo. Uic'ing "%~1"
%QTDIR%\bin\uic "%~1" -o "%~2"
goto:eof

:execRcc
:: arg0 is filename
:: arg1 is output file
call:LOG_MESSAGE "Rcc'ing %~1"
echo. Rcc'ing "%~1"
%QTDIR%\bin\rcc "%~1" -o "%~2"
goto:eof